﻿using System;

namespace PublicEntity
{
    /// <summary>
    /// 返回对象(带总条数),默认值为Bol=True,Message=操作成功
    /// </summary>
    public class ResponseList : ResponseList<object>
    {

    }

    /// <summary>
    /// 返回对象(带总条数),默认值为Bol=True,Message=操作成功
    /// </summary>
    public class ResponseList<T> : ResponseBaseResult<T>
    {
        /// <summary>
        /// 默认成功的实例化
        /// </summary>
        public ResponseList() : base() { }

        /// <summary>
        /// 是否成功的实例化
        /// </summary>
        /// <param name="Bol">是否成功</param>
        public ResponseList(bool Bol) : base(Bol) { }

        /// <summary>
        /// 记录条数
        /// </summary>
        public int Count { get; set; }

        /// <summary>
        /// 自定义隐式转换
        /// </summary>
        /// <param name="a"></param>
        public static implicit operator ResponseList(ResponseList<T> a)
        {
            return new ResponseList
            {
                Bol = a.Bol,
                Message = a.Message,
                Data = a.Data,
                Status = a.Status,
                Count = a.Count
            };
        }

        /// <summary>
        /// 自定义隐式转换
        /// </summary>
        /// <param name="a"></param>
        public static implicit operator ResponseList<T>(ResponseList a)
        {
            var res = new ResponseList<T>
            {
                Bol = a.Bol,
                Message = a.Message,
                Status = a.Status,
                Count = a.Count
            };
            if (a.Data != DBNull.Value && a.Data != null && (a.Data is T))
            {
                res.Data = (T)a.Data;
            }
            return res;
        }
    }
}
